package com.ftg.learn.bus.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.learn.bus.VO.busUseRegidtrationVo;
import com.ftg.learn.bus.entity.BusUseRegistration;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 公车使用登记表 Mapper 接口
 * </p>
 *
 * @author LSY
 * @since 2022-03-21
 */
public interface BusUseRegistrationMapper extends BaseMapper<BusUseRegistration> {


    /**
     * 通过公车信息表id与公车信息表中负责人id查询出
     * 相应的公车信息数据和负责人信息数据
     * @param bid
     * @return
     */
    @Select("select a.bid,b.receiver,c.dname,c.dphone from " +
            "sys_bus_info as a left join sys_bus_info as b on " +
            "a.bid = b.bid left join sys_director as c on b.did = c.did where " +
            "a.bid = #{param1}")
    Map<String,Object> selectAutoInfor(Long bid);


    /**
     * 根据公车的名进行查询
     * @param
     * @return
     */
    @Select("SELECT a.* FROM sys_bus_use_registration AS a LEFT JOIN sys_bus_info AS b ON a.bid = b.bid " +
            "WHERE b.bus_name like CONCAT('%',#{param1},'%')") //CONCAT('%',,'%')
    List<BusUseRegistration> busShowByName(@Param("bus_name") String bus_name);


    /**
     * 根据公车的名进行分页
     * @param pagination
     * @return
     */
    @Select("SELECT a.* FROM sys_bus_use_registration AS a LEFT JOIN sys_bus_info AS b ON " +
            "a.bid = b.bid WHERE b.bus_name like CONCAT('%',#{bus_name},'%')")
    List<BusUseRegistration> showBusName(Page<BusUseRegistration> pagination, String bus_name);

    /**
     * 根据公车的名进行分页
     * @param pagination
     * @return
     */
    @Select("SELECT a.*,b.bus_name FROM sys_bus_use_registration AS a LEFT JOIN sys_bus_info AS b ON a.bid = b.bid " +
            "where a.status = 0")
    List<busUseRegidtrationVo> showBusNamePage(Page<busUseRegidtrationVo> pagination);

    /**
     * 查询 查询该车是否已有使用登记并且取到end_mileage
     * @param bid
     * @param
     * @return
     */
    @Select("select bid,end_mileage from sys_bus_use_registration where bid = #{param1}")
    List<Map<String,Object>> selectAutoInforoldend_place(Long bid);


    /**
     * 插入根据公车信息表ID自动查询出来的值
     * @param bid
     * @param dname
     * @param dphone
     * @param receiver
     * @return
     */
    @Insert("insert into sys_bus_use_registration (bid,dname,dphone,receiver,user_name,user_phone,start_place,end_place,"+
            "start_mileage,end_mileage,borrow_time,is_special,actual_purpose) values("+
            "#{param1},#{param2},#{param3},#{param4},#{param5},#{param6},#{param7},#{param8},#{param9},#{param10},#{param11},#{param12},#{param13})")
    boolean insertAutoInfor(Long bid,String dname,String dphone,String receiver,String user_name,String user_phone,
                            String start_place,String end_place,String start_mileage,String end_mileage,String borrow_time,
                            String is_special,String actual_purpose);

    /**
     * 根据公车登记表id进行查询
     * @param burid
     * @return
     */
    @Select("select * from sys_bus_use_registration where burid = #{param1}")
    List<BusUseRegistration> selectById1(Long burid);

    /**
     * 查询公车表里的bid,bus_name
     * @return
     */
    @Select("SELECT bid,bus_name FROM sys_bus_info")
    List<Map<String,String>> showAllName();


}
